# -*- coding: utf-8 -*-
from flask import Blueprint, render_template, request
from web.models.food import FoodCat

route_food = Blueprint('food_page', __name__)


@route_food.route("/index")
def index():
    return render_template("food/index.html")


@route_food.route("/info")
def info():
    return render_template("food/info.html")


@route_food.route("/set")
def set():
    return render_template("food/set.html")


@route_food.route("/cat")
def cat():
    return render_template("food/cat.html")


@route_food.route("/cat-set")
def catSet():
    '''添加和编辑页面'''
    if request.method == "GET":
        resp_data = {}
        req = request.args
        id = str(req.get('id', 0))
        user_info = None
        if id:  # 是否传id值来区分是 编辑的请求 / 展示请求
            # 有问题这里
            user_info = FoodCat.query.filter_by(id=id).first()
        resp_data['info'] = user_info
        resp_data['current'] = 'cat'
        return render_template('food/cat_set.html', **resp_data)

    return render_template("food/cat_set.html")
